"use strict";
const common_vendor = require("../../common/vendor.js");
const __unplugin_components_2 = () => "../../node-modules/wot-design-uni/components/wd-button/wd-button.js";
const __unplugin_components_1 = () => "../../node-modules/wot-design-uni/components/wd-loading/wd-loading.js";
const __unplugin_components_0 = () => "../../node-modules/wot-design-uni/components/wd-icon/wd-icon.js";
if (!Array) {
  const _component_wd_icon = __unplugin_components_0;
  const _component_wd_loading = __unplugin_components_1;
  const _component_wd_button = __unplugin_components_2;
  const _component_layout_default_uni = common_vendor.resolveComponent("layout-default-uni");
  (_component_wd_icon + _component_wd_loading + _component_wd_button + _component_layout_default_uni)();
}
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  __name: "result",
  setup(__props) {
    const analysisResult = common_vendor.ref(null);
    const loading = common_vendor.ref(true);
    const error = common_vendor.ref(null);
    const route = common_vendor.useRoute();
    common_vendor.useRouter();
    const emotionalStateConfig = common_vendor.computed(() => ({
      积极: {
        color: "#36D399",
        bgColor: "#E6F7EE",
        description: "双方交流氛围愉快，充满正面能量"
      },
      中性: {
        color: "#FFAB00",
        bgColor: "#FFF4E0",
        description: "交流比较平淡，需要进一步加强情感连接"
      },
      消极: {
        color: "#FF6B8B",
        bgColor: "#FEE0E6",
        description: "交流中存在一定的负面情绪，需要注意沟通方式"
      }
    }));
    common_vendor.onMounted(() => {
      try {
        // 获取路由参数
        let resultParam = null;
        // 尝试从route对象获取
        if (route && route.query && route.query.result) {
          resultParam = route.query.result;
          console.log("从route获取到结果参数:", resultParam);
        } else {
          // 尝试从getCurrentPages获取
          try {
            const pages = getCurrentPages();
            if (pages && pages.length > 0) {
              const currentPage = pages[pages.length - 1];
              if (currentPage && currentPage.options && currentPage.options.result) {
                resultParam = currentPage.options.result;
                // console.log("从getCurrentPages获取到结果参数:", resultParam);
              }
            }
          } catch (e) {
            console.log("尝试从getCurrentPages获取参数失败:", e);
          }
        }
        
        if (!resultParam) {
          console.warn("未找到任何分析结果参数");
          error.value = "未找到分析结果";
          return;
        }
        
        // 解码参数
        const decodedResult = decodeURIComponent(resultParam);
        // console.log("解码后的原始结果:", decodedResult);
        
        // 解析JSON
        const parsedResult = JSON.parse(decodedResult);
        // console.log("解析后的结果对象:", parsedResult);
        
        // 简化提取content的逻辑
        let analysisContent;
        
        // 检查是否是标准API返回格式 (choices[0].message.content)
        if (parsedResult.choices && parsedResult.choices[0] && parsedResult.choices[0].message && parsedResult.choices[0].message.content) {
          analysisContent = parsedResult.choices[0].message.content;
          // console.log("从标准API格式提取的content:", analysisContent);
          
          // 如果content还是字符串，尝试解析为JSON
          if (typeof analysisContent === 'string') {
            try {
              analysisContent = JSON.parse(analysisContent);
              // console.log("解析content后的JSON对象:", analysisContent);
            } catch (parseError) {
              // console.warn("content不是有效的JSON，但我们会将其作为文本处理:", parseError);
              // 这里不使用默认值，而是使用实际内容
              analysisContent = { content: analysisContent };
            }
          }
        } else {
          // 如果不是标准格式，直接使用解析后的结果
          analysisContent = parsedResult;
          // console.log("直接使用解析后的结果作为分析内容");
        }
        
        // 验证必要字段是否存在
        if (!analysisContent || typeof analysisContent !== 'object') {
          throw new Error("分析内容格式无效");
        }
        
        // 不使用默认值，而是直接使用API返回的实际结果
        // 这样可以确保每次都显示最新的分析结果
        analysisResult.value = enhanceAnalysisResult(analysisContent);
        // console.log("最终显示的分析结果:", analysisResult.value);
        
      } catch (e) {
        error.value = "解析分析结果时出错: " + e.message;
        console.error("解析分析结果失败:", e);
        // 发生错误时不再显示默认值，而是显示错误信息
        // 这样用户会知道系统出了问题，而不是看到不准确的默认结果
      } finally {
        loading.value = false;
      }
    });
    function enhanceAnalysisResult(result) {
      // 只提取API返回的实际字段，不使用默认值
      // 确保每次都显示最新的分析结果，而不是固定的默认内容
      const enhancedResult = {
        emotionalState: result.emotionalState,
        对方心理活动: result.对方心理活动,
        对方看法: result.对方看法,
        兴趣程度: result.兴趣程度,
        回复建议: result.回复建议,
        话题建议: result.话题建议,
        接话技巧: result.接话技巧,
        留下好印象方法: result.留下好印象方法,
        // 兼容可能的英文字段名
        impressionMethods: result.impressionMethods,
        conversationSkills: result.conversationSkills,
        topicSuggestions: result.topicSuggestions,
        replySuggestions: result.replySuggestions,
        interestLevel: result.interestLevel
      };
      return enhancedResult;
    }
    function navigateBack() {
      common_vendor.index.switchTab({ url: "/pages/index/index" });
    }
    function reAnalyze() {
      common_vendor.index.navigateBack({ delta: 1 });
    }
    return (_ctx, _cache) => {
      var _a, _b;
      return common_vendor.e({
        a: common_vendor.p({
          name: "arrow-left",
          size: "20px"
        }),
        b: common_vendor.o(navigateBack),
        c: loading.value
      }, loading.value ? {
        d: common_vendor.p({
          type: "ring",
          size: "40px",
          color: "#FF6B8B"
        })
      } : error.value ? {
        f: common_vendor.p({
          name: "warning-circle",
          size: "60px",
          color: "#FF6B8B"
        }),
        g: common_vendor.t(error.value),
        h: common_vendor.o(reAnalyze),
        i: common_vendor.p({
          type: "primary"
        })
      } : analysisResult.value ? common_vendor.e({
        k: common_vendor.t(analysisResult.value ? analysisResult.value.emotionalState : "中性"),
        l: analysisResult.value ? ((_a = emotionalStateConfig.value[analysisResult.value.emotionalState]) == null ? void 0 : _a.bgColor) || "#FFF4E0" : "#FFF4E0",
        m: analysisResult.value ? ((_b = emotionalStateConfig.value[analysisResult.value.emotionalState]) == null ? void 0 : _b.color) || "#FFAB00" : "#FFAB00",
        n: analysisResult.value && (analysisResult.value.对方看法 || analysisResult.value.otherOpinions)
      }, analysisResult.value && (analysisResult.value.对方看法 || analysisResult.value.otherOpinions) ? {
        o: common_vendor.t(analysisResult.value.对方看法 || analysisResult.value.otherOpinions)
      } : {}, {
        p: analysisResult.value && (analysisResult.value.兴趣程度 || analysisResult.value.interestLevel)
      }, analysisResult.value && (analysisResult.value.兴趣程度 || analysisResult.value.interestLevel) ? {
        q: common_vendor.t(analysisResult.value.兴趣程度 || analysisResult.value.interestLevel)
      } : {}, {
        r: analysisResult.value && (analysisResult.value.对方心理活动 || analysisResult.value.psychologicalActivity)
      }, analysisResult.value && (analysisResult.value.对方心理活动 || analysisResult.value.psychologicalActivity) ? {
        s: common_vendor.t(analysisResult.value.对方心理活动 || analysisResult.value.psychologicalActivity)
      } : {}) : {}, {
        e: error.value,
        j: analysisResult.value,
        t: analysisResult.value && (analysisResult.value.回复建议 || analysisResult.value.replySuggestions) && ((analysisResult.value.回复建议 || []).length > 0 || (analysisResult.value.replySuggestions || []).length > 0)
      }, analysisResult.value && (analysisResult.value.回复建议 || analysisResult.value.replySuggestions) && ((analysisResult.value.回复建议 || []).length > 0 || (analysisResult.value.replySuggestions || []).length > 0) ? {
        v: common_vendor.p({
          name: "message-circle",
          size: "20px",
          color: "#FF6B8B"
        }),
        w: common_vendor.f(analysisResult.value ? (analysisResult.value.回复建议 || analysisResult.value.replySuggestions || []) : [], (reply, index, i0) => {
          return {
            a: common_vendor.t(index + 1),
            b: common_vendor.t(reply),
            c: index
          };
        })
      } : {}, {
        x: analysisResult.value && (analysisResult.value.话题建议 || analysisResult.value.topicSuggestions)
      }, analysisResult.value && (analysisResult.value.话题建议 || analysisResult.value.topicSuggestions) ? {
        y: common_vendor.p({
          name: "star",
          size: "20px",
          color: "#FFAB00"
        }),
        z: common_vendor.f(Array.isArray(analysisResult.value.话题建议) ? analysisResult.value.话题建议 : Array.isArray(analysisResult.value.topicSuggestions) ? analysisResult.value.topicSuggestions : [analysisResult.value.话题建议 || analysisResult.value.topicSuggestions || '']
          .filter(item => item && typeof item === 'string' && item.trim()),
          (topic, index) => ({
            a: index,
            b: topic
          }))
      } : {}, {
        A: analysisResult.value && (analysisResult.value.接话技巧 || analysisResult.value.conversationSkills)
      }, analysisResult.value && (analysisResult.value.接话技巧 || analysisResult.value.conversationSkills) ? {
        B: common_vendor.p({
          name: "lightbulb",
          size: "20px",
          color: "#36D399"
        }),
        C: common_vendor.t(analysisResult.value.接话技巧 || analysisResult.value.conversationSkills)
      } : {}, {
        D: analysisResult.value && (analysisResult.value.留下好印象方法 || analysisResult.value.impressionMethods)
      }, analysisResult.value && (analysisResult.value.留下好印象方法 || analysisResult.value.impressionMethods) ? {
        E: common_vendor.p({
          name: "heart",
          size: "20px",
          color: "#FF6B8B"
        }),
        F: common_vendor.t(analysisResult.value.留下好印象方法 || analysisResult.value.impressionMethods)
      } : {}, {
        G: common_vendor.o(reAnalyze),
        H: common_vendor.o(navigateBack)
      });
    };
  }
});
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-3578954a"]]);
wx.createPage(MiniProgramPage);
